import entity.MasterNumber;
import entity.Person;

import java.util.*;
import java.util.stream.Stream;

public class PersonService {

  private Map<List<String>, Optional<PersonSet>> people;

  public PersonService() {
    this.people = new HashMap<>();
    people.put(Arrays.asList("1"), Optional.of(PersonSetDataProvider.providePersonSetWithNumber1()));
    people.put(Arrays.asList("1", "2"), Optional.of(PersonSetDataProvider.providePersonSetWithNumber1And2()));
  }

  public Map<List<String>, Optional<PersonSet>> getPeople(){
    return people;
  }

  public Stream<Person> getPersonByMasterNumbers(List<MasterNumber> numbers) {
    //TODO: Add the code to return people by numbers
    // Use groupToPeople() method
    List<String> masterNumbers = new ArrayList<>();
    for(MasterNumber m: numbers){
      masterNumbers.add(m.getMasterNumber());
    }
    if(people.get(masterNumbers)!=null){
      return people.get(masterNumbers).get().groupToPeople();
    } else {
      return Stream.empty();
    }
  }

}
